package com.ruoyi.web.controller.system;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TestPlan;
import com.ruoyi.system.service.ITestPlanService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * test_planController
 * 
 * @author ruoyi
 * @date 2022-10-07
 */
@Controller
@RequestMapping("/system/test_plan")
public class TestPlanController extends BaseController
{
    private String prefix = "system/test_plan";

    @Autowired
    private ITestPlanService testPlanService;

    @RequiresPermissions("system:test_plan:view")
    @GetMapping()
    public String test_plan()
    {
        return prefix + "/test_plan";
    }

    /**
     * 查询test_plan列表
     */
    @RequiresPermissions("system:test_plan:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TestPlan testPlan)
    {
        startPage();
        List<TestPlan> list = testPlanService.selectTestPlanList(testPlan);
        return getDataTable(list);
    }

    /**
     * 导出test_plan列表
     */
    @RequiresPermissions("system:test_plan:export")
    @Log(title = "test_plan", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TestPlan testPlan)
    {
        List<TestPlan> list = testPlanService.selectTestPlanList(testPlan);
        ExcelUtil<TestPlan> util = new ExcelUtil<TestPlan>(TestPlan.class);
        return util.exportExcel(list, "test_plan数据");
    }

    /**
     * 新增test_plan
     */
    @GetMapping("/add")
    public String add(ModelMap mmap)
    {
        mmap.put("TestItem", testPlanService.selectTestItemName());
        return prefix + "/add";
    }

    /**
     * 新增保存test_plan
     */
    @RequiresPermissions("system:test_plan:add")
    @Log(title = "test_plan", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TestPlan testPlan)
    {
        return toAjax(testPlanService.insertTestPlan(testPlan));
    }

    /**
     * 修改test_plan
     */
    @RequiresPermissions("system:test_plan:edit")
    @GetMapping("/edit/{planId}")
    public String edit(@PathVariable("planId") Long planId, ModelMap mmap)
    {
        TestPlan testPlan = testPlanService.selectTestPlanByPlanId(planId);
        mmap.put("testPlan", testPlan);
        return prefix + "/edit";
    }

    /**
     * 修改保存test_plan
     */
    @RequiresPermissions("system:test_plan:edit")
    @Log(title = "test_plan", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TestPlan testPlan)
    {
        return toAjax(testPlanService.updateTestPlan(testPlan));
    }

    /**
     * 删除test_plan
     */
    @RequiresPermissions("system:test_plan:remove")
    @Log(title = "test_plan", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(testPlanService.deleteTestPlanByPlanIds(ids));
    }
}
